<?php

namespace App\Models\Depot;

use Illuminate\Database\Eloquent\Model;
use App\Models\Region as RegionModel;

class Back extends Model
{

    protected $table = 'depot_back';

    protected $dateFormat = 'U';

    const CREATED_AT = 'createtime';

    const UPDATED_AT = null;

    protected $guarded = [];

    protected $appends = [
        'address_text', // 地址
    ];

    public function getAddressTextAttribute()
    {
        $egion = '';

        $province = RegionModel::where('code', $this->attributes['province'])->value('name');

        if($province)
        {
            $egion = $province;
        }

        $city = RegionModel::where('code', $this->attributes['city'])->value('name');

        if($city)
        {
            $egion .= $city;
        }

        $district = RegionModel::where('code', $this->attributes['district'])->value('name');

        if($district)
        {
            $egion .= $district;
        }

        return $egion . $this->attributes['address'];
    }
}
